package com.lx.patterns.responsibility;

/**
 * @ClassName Handler
 * @Description: //todo
 * @Author: 落雪
 * @CreateDate: 2025/2/11 20:25
 * @UpdateUser: 落雪
 * @UpdateDate: 2025/2/11 20:25
 * @UpdateRemark:
 * @Version: 1.0
 */
public abstract class Handler {

    protected static final int LEAVE_DAY_ONE = 1;
    protected static final int LEAVE_DAY_THREE = 3;
    protected static final int LEAVE_DAY_SEVEN = 7;


    private int startDay;

    private int endDay;

    private Handler nextHandler;

    public Handler(int numStart){
        this.startDay = numStart;
    }

    public Handler(int numStart,int numEnd){
        this.startDay = numStart;
        this.endDay = numEnd;
    }

    public void setNextHandler(Handler nextHandler){
        this.nextHandler = nextHandler;
    }

    public final void submitLeave(LeaveRequest request){
        if(request.getDay() >= startDay){
            if(request.getDay() < endDay){
                this.handleLeave(request);
            }else{
                if(this.nextHandler != null){
                    this.nextHandler.submitLeave(request);
                }else{
                    System.out.println("请假天数过长，没有人处理");
                }
            }
        }else{
            System.out.println("请假天数过短，没有人处理");
        }
    }

    protected abstract void handleLeave(LeaveRequest request);

}
